﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Projet_IMA.Environnement;
using System.Drawing;
using Projet_IMA.Base;
using Projet_IMA.Object3D;
using Projet_IMA.Unsafe;

namespace Projet_IMA.Environnement
{

    public class SceneGrille
    {

        private int widthScreen;
        private int heigthScreen;
        private int longeur;
        private List<CachePoint> cacheOrthogonal;
        private List<CachePoint> cachePerspective;
        Couleur CGrille = new Couleur(0.7f, 0.7f, 0.7f);

        public SceneGrille(int widthScreen, int heigthScreen, int longeur)
        {
            this.widthScreen = widthScreen;
            this.heigthScreen = heigthScreen;
            this.longeur = longeur;

            this.cacheOrthogonal = new List<CachePoint>();
            this.cachePerspective = new List<CachePoint>();

            MakeCacheOrthogonal();
            MakeCachePerspective();
        }

        private void MakeCacheOrthogonal()
        {
            V3 vecteurHoriZX = new V3(1, 0, 0);
            V3 vecteurVertiXZ = new V3(0, 0, 1);

            for (int u = 0; u < widthScreen; u += 20)
                cacheOrthogonal.Add((new Ligne(new V3(u, 0, 0), vecteurVertiXZ, heigthScreen, CGrille, 1.0f).GetCache()));


            for (int v = 0; v < heigthScreen; v += 20)
                cacheOrthogonal.Add((new Ligne(new V3(0, 0, v), vecteurHoriZX, widthScreen, CGrille, 1.0f).GetCache()));
        }

        private void MakeCachePerspective()
        {
            V3 vecteurY = new V3(0, 1, 0);
            V3 vecteurX = new V3(1, 0, 0);

            for (int u = 0; u <= longeur; u += 50)
                cachePerspective.Add((new Ligne(new V3(u, 0, 0), vecteurY, longeur, CGrille, 1.0f).GetCache()));


            for (int v = 0; v <= longeur; v += 50)
                cachePerspective.Add((new Ligne(new V3(0, v, 0), vecteurX, longeur, CGrille, 1.0f).GetCache()));
        }

        public List<CachePoint> GetCacheGrille(EProjectionType type)
        {
            if (type == EProjectionType.Orthogonale)
                return this.cacheOrthogonal;
            else
                return this.cachePerspective;
        }

    }
}

